import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/components/back_btn_icon.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/app/tools/color_const.dart';
import 'package:share_fit/generated/locales.g.dart';

import 'logic.dart';

class CountryPage extends StatelessWidget {
  CountryPage({Key? key}) : super(key: key);

  final logic = Get.put(CountryLogic());
  final state = Get.find<CountryLogic>().state;
  bool toMainPage = false;

  @override
  Widget build(BuildContext context) {
    Map country = logic.read('country_selected_mode', defaultValue: {});
    if(country.isNotEmpty && country.containsKey('name')) {
      logic.updateCountryName(country['name']);
    }

    if(Get.arguments!=null) {
      Map<String, dynamic> params = Get.arguments;
      if(params.containsKey('toMainPage')) {
        toMainPage = params['toMainPage'];
      }
    }

    return PopScope(
        canPop: false,
        onPopInvoked: (didPop)=>(Get.offNamed('/login', arguments: {'toMainPage': toMainPage})),
        child: Scaffold(
      appBar: AppBar(
        title: Text('', style: TextStyle(fontSize: 54.sp, color: ColorConst.btnFontColor),),
        centerTitle: true,
        leading: BackBtnIcon(onTap: () => Get.offNamed('/login', arguments: {'toMainPage': toMainPage})),
      ),
      body: Container(
        padding: EdgeInsets.only(top: 100.h),
        child: Column(
          children: [
            Container(
              alignment: Alignment.center,
              width: 280.w,
              height: 280.w,
              child: Image.asset('assets/images/home/ic_launcher.png'),
            ),
            // FutureBuilder<AppInfo>(
            //   future: InstalledApps.getAppInfo(appInfo['packageName']),
            //   builder:
            //       (BuildContext buildContext, AsyncSnapshot<AppInfo> snapshot) {
            //     return snapshot.connectionState == ConnectionState.done
            //         ? snapshot.hasData
            //         ?Column(
            //       children: [
            //         Container(
            //           alignment: Alignment.center,
            //           width: 280.w,
            //           height: 280.w,
            //           child: Image.memory(snapshot.data!.icon!),
            //         ),],)
            //         : Container(
            //       margin: EdgeInsets.only(top: 82.h),
            //       alignment: Alignment.center,
            //       width: 280.w,
            //       height: 280.w,)
            //         : Center();
            //   },),
            SizedBox(height: 168.h,),
            Ink(
              height: 162.h,
              decoration: BoxDecoration(
                color: Colors.white,
              ),
              child: InkResponse(
                splashColor: ColorConst.activeColor,
                highlightShape: BoxShape.rectangle,
                highlightColor: ColorConst.activeColor,
                containedInkWell: true,
                onTap: () {Get.offNamed('/login/country/list', arguments: {'toMainPage': toMainPage});},
                child: Container(
                  padding: EdgeInsets.fromLTRB(103.w, 0, 60.h, 0),
                  width: 1.sw,
                  child: Row(
                    children: [
                      Expanded(child: Text(LocaleKeys.country_area_selected.ts, style: TextStyle(fontSize: 42.sp, color: ColorConst.btnFontColor),),),
                      GetBuilder<CountryLogic>(
                          id: 'selected_country_name',
                          builder: (_){
                            return Text(state.selectedCountryName, style: TextStyle(fontSize: 42.sp, color: ColorConst.btnFontColor),);
                          }),
                      SizedBox(width: 77.w,),
                      Icon(Icons.arrow_forward_ios, size: 16,),
                    ],
                  ),
                ),
              ),
            ),
          ],),
      ),));
  }
}
